package com.repository.common;


import java.util.Collections;
import java.util.List;

/**
 *
 *  分页返回实体
 * @param <T>
 */
public class PageResult<T> {
    private Integer pageNo=1;

    private Integer pageSize=20;

    private Integer total=0;

    private Integer totalPages =0;

    private List<T> result=Collections.emptyList();

    private Integer start =1;

    private Integer end=0;

    public void setRecords(List<T> result){
        this.result = result;
        if (result !=null && result.size()>0){
            setTotal(result.size());
        }
    }

    public void setTotal(int size) {
        this.total=total;
        if (this.pageSize>0){
            this.totalPages=(total/this.pageSize) + (total%this.pageSize==0?0:1);
        }else{
            this.totalPages=0;
        }
    }

    public void setPageSize(Integer pageSize){
        this.pageSize=pageSize;
    }

    public void setPageNo(Integer pageNo){
        this.pageNo=pageNo;
    }
}
